using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

// TODO: replace this with the type you want to read.
using TRead = WindowsGame1.TileMap;

namespace WindowsGame1
{
    class TilemapReader : ContentTypeReader<TRead>
    {
        protected override TRead Read(ContentReader input, TRead existingInstance)
        {
            List<TileMapLayer> layers = new List<TileMapLayer>();
            int mapWidth = input.ReadInt32();
            int mapHeight = input.ReadInt32();
            int layerCount = input.ReadInt32();
            for (int i = 0; i < layerCount; i++)
            {
                TileMapLayer layer = new TileMapLayer(mapWidth, mapHeight);
                for (int y = 0; y < mapHeight; y++)
                    for (int x = 0; x < mapWidth; x++)
                        layer.SetTile(x, y, input.ReadInt32());
                layers.Add(layer);
            }
            return new TRead(mapWidth, mapHeight, layers);
        }
    }
}
